package org.brownflat.watergate.resources.mysql;

import org.brownflat.watergate.resources.MySqlUpgrade;
import org.springframework.stereotype.Component;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
@Component
public class Upgrade0005Commit implements MySqlUpgrade {

    private static final int VERSION = 5;

    @Override
    public int getSequence() {
        return VERSION;
    }

    @Override
    public String getSql() {
        return "CREATE TABLE `wgate_commit` (\n"
                + " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + " `message` text NULL,\n"
                + " `revision` int(11) NOT NULL,\n"
                + " `branch` int(11) NOT NULL,\n"
                + "  `created_at` timestamp NOT NULL,\n"
                + "  `updated_at` timestamp NOT NULL,\n"
                + "  PRIMARY KEY (`id`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n"
                + "\n"
                + "CREATE TABLE `wgate_branch`(\n"
                + " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + " `name` varchar(100) NOT NULL,\n"
                + " `path` tinytext NOT NULL,\n"
                + " `repository` int(11) NOT NULL,\n"
                + "  `created_at` timestamp NOT NULL,\n"
                + "  `updated_at` timestamp NOT NULL,\n"
                + "  PRIMARY KEY (`id`),\n"
                + "  UNIQUE KEY `name_UNIQUE` (`name`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n"
                + "\n"
                + "CREATE TABLE `wgate_repository`(\n"
                + " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + " `name` varchar(255) NOT NULL,\n"
                + " `url` tinytext NOT NULL,\n"
                + " `username` varchar(255) NOT NULL,\n"
                + " `password` varchar(255) NOT NULL,\n"
                + "  `created_at` timestamp NOT NULL,\n"
                + "  `updated_at` timestamp NOT NULL,\n"
                 + " PRIMARY KEY (`id`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n"
                + "\n"
                + "CREATE TABLE `wgate_commit_element`(\n"
                + " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + " `path` tinytext NOT NULL,\n"
                + " `commit` int(11) NOT NULL,\n"
                + " `element_action` varchar(50) NOT NULL,\n"
                + " `created_at` timestamp NOT NULL,\n"
                + " `updated_at` timestamp NOT NULL,\n"
                 + " PRIMARY KEY (`id`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n";
    }

    @Override
    public String getName() {
        return "Create commit structure";
    }
}
